﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:LOAN_CONTRACTFILES
	/// </summary>
	public partial class LOAN_CONTRACTFILES : BaseDAL<GSLMS.Entity.TB_LOAN_CONTRACTFILES>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public LOAN_CONTRACTFILES()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_LOAN_CONTRACTFILES model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_TMPID", model.TMPID),
								new OracleParameter("P_CONTYPE", model.CONTYPE),
								new OracleParameter("P_CONNO", model.CONNO),
								new OracleParameter("P_SAVEURL", model.SAVEURL),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_MODIFYDATE", model.MODIFYDATE),
								new OracleParameter("P_LASTPRINT", model.LASTPRINT),
								new OracleParameter("P_PRINTDATE", model.PRINTDATE),
								new OracleParameter("P_PRINTCOUNT", model.PRINTCOUNT)};
  
			for (int i = 0; i < 13; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_contractfiles_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_LOAN_CONTRACTFILES model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_TMPID", model.TMPID),
								new OracleParameter("P_CONTYPE", model.CONTYPE),
								new OracleParameter("P_CONNO", model.CONNO),
								new OracleParameter("P_SAVEURL", model.SAVEURL),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_MODIFYBY", model.MODIFYBY),
								new OracleParameter("P_MODIFYDATE", model.MODIFYDATE),
								new OracleParameter("P_LASTPRINT", model.LASTPRINT),
								new OracleParameter("P_PRINTDATE", model.PRINTDATE),
								new OracleParameter("P_PRINTCOUNT", model.PRINTCOUNT)};
  
			for (int i = 0; i < 13; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_contractfiles_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_contractfiles_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_LOAN_CONTRACTFILES DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_LOAN_CONTRACTFILES model = new GSLMS.Entity.TB_LOAN_CONTRACTFILES();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["TMPID"]!=null && dr["TMPID"].ToString()!="")
				{
					model.TMPID=OracleHelper.ToLong(dr["TMPID"].ToString());
				}
				if(dr["CONTYPE"]!=null && dr["CONTYPE"].ToString()!="")
				{
					model.CONTYPE=dr["CONTYPE"].ToString();
				}
				if(dr["CONNO"]!=null && dr["CONNO"].ToString()!="")
				{
					model.CONNO=dr["CONNO"].ToString();
				}
				if(dr["SAVEURL"]!=null && dr["SAVEURL"].ToString()!="")
				{
					model.SAVEURL=dr["SAVEURL"].ToString();
				}
				if(dr["CREATEBY"]!=null && dr["CREATEBY"].ToString()!="")
				{
					model.CREATEBY=dr["CREATEBY"].ToString();
				}
				if(dr["CREATEDATE"]!=null && dr["CREATEDATE"].ToString()!="")
				{
					model.CREATEDATE=DateTime.Parse(dr["CREATEDATE"].ToString());
				}
				if(dr["MODIFYBY"]!=null && dr["MODIFYBY"].ToString()!="")
				{
					model.MODIFYBY=dr["MODIFYBY"].ToString();
				}
				if(dr["MODIFYDATE"]!=null && dr["MODIFYDATE"].ToString()!="")
				{
					model.MODIFYDATE=DateTime.Parse(dr["MODIFYDATE"].ToString());
				}
				if(dr["LASTPRINT"]!=null && dr["LASTPRINT"].ToString()!="")
				{
					model.LASTPRINT=dr["LASTPRINT"].ToString();
				}
				if(dr["PRINTDATE"]!=null && dr["PRINTDATE"].ToString()!="")
				{
					model.PRINTDATE=DateTime.Parse(dr["PRINTDATE"].ToString());
				}
				if(dr["PRINTCOUNT"]!=null && dr["PRINTCOUNT"].ToString()!="")
				{
                    model.PRINTCOUNT = OracleHelper.ToInt(dr["PRINTCOUNT"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_LOAN_CONTRACTFILES GetByID(long ID)
		{
			GSLMS.Entity.TB_LOAN_CONTRACTFILES sModel = new GSLMS.Entity.TB_LOAN_CONTRACTFILES();
			string sql = "";
			sql = "select * from TB_LOAN_CONTRACTFILES where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_LOAN_CONTRACTFILES> GetList(GSLMS.Entity.TB_LOAN_CONTRACTFILES searchParam)
		{
			var list=new List<GSLMS.Entity.TB_LOAN_CONTRACTFILES>();
			DataTable dt = null;
			string tblName = "TB_LOAN_CONTRACTFILES";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_LOAN_CONTRACTFILES model = new GSLMS.Entity.TB_LOAN_CONTRACTFILES();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

